/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package th.quartz;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.TriggerUtils;

/**
 *
 * @author Administrator
 */
@Singleton
public class SchedulerManager {

    Scheduler scheduler;

    @Inject
    public SchedulerManager(Scheduler scheduler) {
        this.scheduler = scheduler;
    }

    /**
     * TODO: fix to use annotation, maybe add job dynamically at module
     * @throws SchedulerException
     */
    public void start() throws SchedulerException {
        JobDetail mailJob = new JobDetail("batch", "batch_group", DeactivateUserProcess.class);
        JobDetail smsJob = new JobDetail("sms", "sms_group", SmsProcess.class);
//        JobDetail piJob = new JobDetail("batch", "batch_group", PiProcess.class);
        Trigger minute = TriggerUtils.makeDailyTrigger("sms_trigger", 8, 30);
        Trigger minute2 = TriggerUtils.makeDailyTrigger("deactivate_trigger", 00, 30);
 //       Trigger minute2 = TriggerUtils.makeHourlyTrigger("sms_trigger");
        scheduler.scheduleJob(smsJob, minute);
        scheduler.scheduleJob(mailJob, minute2);
        scheduler.start();
    }

    public void shutdown() throws SchedulerException {
        scheduler.shutdown();
    }
    
}
